const gulp = require('gulp')
const ts = require('gulp-typescript')
const fs = require('fs-extra')

const tsProject = ts.createProject('tsconfig.json')

function compileTS () {
  return tsProject.src()
  .pipe(tsProject())
  .pipe(gulp.dest('lib'))
}

function clearLib (cb) {
  fs.removeSync('./lib/')
  cb()
}

function watch (cb) {
  gulp.watch(tsProject.config.include, gulp.series(clearLib, compileTS))
  cb()
}


exports.watch = watch
exports.default = gulp.series(clearLib, compileTS)